import utils from "../utils";

export default class ObjectTpl {
    private KEY_STR = "";
    private defaultVal: any = {};
    constructor(key: string = "OBJECT", defaultVal: any = {}) {
        this.KEY_STR = `PHQ_SYSTEM_${key}_OBJECT_STR`;
        this.defaultVal = defaultVal;
    }
    public Get(): any {
        const val = sessionStorage.getItem(this.KEY_STR) as string;
        return utils.empty(val) ? this.defaultVal : JSON.parse(val);
    }
    public Set(val: any) {
        if (!utils.empty(val)) {
            sessionStorage.setItem(this.KEY_STR, JSON.stringify(val));
        }
    }
    public Remove() {
        sessionStorage.removeItem(this.KEY_STR);
    }
}
